package ase.eleitweg.client.gui.utils;

import java.io.*;

public class FileByteConverter {

	public static byte[] fileToByte(File file) throws IOException {
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

		FileInputStream fileInputStream = new FileInputStream(file);
		byte[] buffer = new byte[16384];
		for (int len = fileInputStream.read(buffer); len > 0; len = fileInputStream.read(buffer)) {
			byteArrayOutputStream.write(buffer, 0, len);

		}
		fileInputStream.close();
		return byteArrayOutputStream.toByteArray();

	}
	
	public static void writeData(byte[] data, File to) throws IOException {
		FileOutputStream fos = new FileOutputStream(to);
		fos.write(data);
		fos.close();
	}

}
